package im.vinci.server.device.controller;

import im.vinci.server.device.domain.Device;
import im.vinci.server.device.domain.wrappers.requests.OTAInfo;
import im.vinci.server.device.domain.wrappers.responses.DeviceUpdateInfo;
import im.vinci.server.device.service.DeviceModifyService;
import im.vinci.server.security.ApiSecurityLabel;
import im.vinci.server.utils.apiresp.ResultObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by henryhome on 9/14/15.
 */
@RestController
@RequestMapping(value = "/vinci/device", produces = "application/json;charset=UTF-8")
public class DeviceModifyController {

    @Autowired
    private DeviceModifyService deviceModifyService;

    private Logger logger = LoggerFactory.getLogger(getClass());

    @RequestMapping(value = "/ota_update", method = RequestMethod.POST)
    public ResultObject<DeviceUpdateInfo> updateViaOTA(@RequestBody OTAInfo otaInfo)
        throws Exception {

        DeviceUpdateInfo updateInfo = deviceModifyService.updateViaOTA(otaInfo);

        return new ResultObject<>(updateInfo);
    }


    @RequestMapping(value = "/add_device", method = RequestMethod.POST)
    @ApiSecurityLabel
    public ResultObject<Device> addDevice(@RequestBody Device device) throws Exception {
        return new ResultObject<>(deviceModifyService.addDevice(device));
    }


}
